package com.example.benefitcommunity.controller;

import com.example.benefitcommunity.entity.BcAddressList;
import com.example.benefitcommunity.entity.BcCommunity;
import com.example.benefitcommunity.entity.Result;
import com.example.benefitcommunity.service.BcCommunityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 社区管理表(BcCommunity)表控制层
 *
 * @author makejava
 * @since 2025-08-06 16:53:16
 */
@Tag(name = "社区")
@CrossOrigin
@RestController
@RequestMapping("bcCommunity")
public class BcCommunityController {
    /**
     * 服务对象
     */
    @Resource
    private BcCommunityService bcCommunityService;

    /**
     * 通过查询数据
     *
     * @param name     姓名
     * @param pagenum  页码
     * @param pagesize 页大小
     * @return 数据
     */
    @Operation(description = "社区查询")
    @GetMapping("list")
    public Result<Object> queryByCommunity(String name, Integer pagenum, Integer pagesize) {
        return this.bcCommunityService.queryByCommunity(name,  pagenum, pagesize);
    }

    @Operation(description = "社区查询1")
    @GetMapping("id")
    public Result<Object> queryByCommunityId(Integer id) {
        return this.bcCommunityService.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param bcCommunity 实体
     * @return 新增结果
     */
    @Operation(description = "新增社区")
    @PostMapping("add")
    public Result<Object> add(@RequestBody BcCommunity bcCommunity) {
        return this.bcCommunityService.insert(bcCommunity);
    }

    /**
     * 编辑数据
     *
     * @param bcCommunity 实体
     * @return 编辑结果
     */
    @Operation(description = "编辑社区")
    @PutMapping("edit")
    public Result<Object> edit(@RequestBody BcCommunity bcCommunity) {
        return this.bcCommunityService.update(bcCommunity);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @Operation(description = "删除社区")
    @DeleteMapping("delete")
    public Result<Object> deleteById(Integer[] id) {
        return this.bcCommunityService.deleteById(id);
    }
}

